#ifndef RESEAU_HPP
#define RESEAU_HPP

#include <QObject>
#include <QTcpServer>
#include <QList>

#include "mainwindow.hpp"
#include "client.hpp"
#include "lobby.hpp"
#include "../../src/idmanager.hpp"

class Client;
class Lobby;
class MainWindow;

class Reseau : public QObject
{
    Q_OBJECT

public:
    Reseau(Lobby * lobby, MainWindow * mainWindow, QObject * parent = 0);
    ~Reseau();

    bool clientExists(const QString & name) const;
    void sendAll(Mid::MessageID mid, const QString & s0);
    void sendAll(Mid::MessageID mid, quint8 i0);
    void sendAll(Mid::MessageID mid, quint8 i0, const QString & s0);
    void sendAll(Mid::MessageID mid, quint8 i0, quint8 i1, qreal r0, const QString & s0);

    QList<Client *> clientList() const;

private:
    QTcpServer * _server;
    QList<Client *> _clients;
    MainWindow * _mainWindow;
    Lobby * _lobby;

signals:
    void serverBound();
    void impossibleToBoundPort(int);

public slots:
    void connect(int port);
    void kick(const QString & name);

private slots:
    void nouvelleConnexion();
    void finConnexion(const QString & name);
    void nouvelleIdentification(const QString & name);
    void nouveauMessage(const QString & message);

};

#endif // RESEAU_HPP
